﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileEncrypt.Encrypt
{
   public class EntryptBase
    {
        protected const int bufferSize=4096;
        private byte[] key = { 0x01, 0x53, 0x25, 0x07, 0x91, 0x11, 0x77, 0x19, 
                                 0x61, 0x36, 0x54, 0xA7, 0xB9, 0x16, 0x56, 0x0A,
                                 0x08, 0x53, 0x25, 0x0F, 0x91, 0x1F, 0x78, 0xD9,
                                 0x62, 0x3A, 0x5D, 0xF7, 0x19, 0x15, 0x56, 0x04 };

        private byte[] iv = { 0x21, 0x35, 0x51, 0x7B, 0x90, 0xCD, 0x1A, 0xDF,
                                0x2C, 0x15, 0x12, 0x97, 0x9A, 0xA2, 0x7C, 0xD7 };

        protected byte[] GetKey(string Key)
        {
            byte[] myKey = new byte[32];
            if (string.IsNullOrEmpty(Key))
            {
                return this.key;
            }
            byte[] tmpkey = ASCIIEncoding.ASCII.GetBytes(Key);
            for (int i = 0; i < 32; i++)
            {
                if (tmpkey.Length > i)
                {
                    myKey[i] = tmpkey[i];
                }
                else
                {
                    myKey[i] = this.key[i];
                }
            }
            return myKey;
        }

        protected byte[] GetIV(string iv)
        {
            byte[] myIV = new byte[16];
            if (string.IsNullOrEmpty(iv))
            {
                return this.iv;
            }
            byte[] tmpIV = ASCIIEncoding.ASCII.GetBytes(iv);
            for (int i = 0; i < 16; i++)
            {
                if (tmpIV.Length > i)
                {
                    myIV[i] = tmpIV[i];
                }
                else
                {
                    myIV[i] = this.iv[i];
                }
            }
            return myIV;
        }
    }
}
